<?php
/**
 * Created by PhpStorm.
 * User: Rain
 * Date: 2018/11/20
 * Time: 9:59
 */

namespace app\admin\model;


use think\Model;

class Invoice extends Model
{
    /**
     * 发票列表
     */
    public function resList($where){
        $query = $this -> where(1);

        // 筛选条件
        $is_where = $where;
        unset($is_where['page']);
        if($is_where) {
            if ($where) {
                // 查询时间日期
                if ($where['start'] && $where['end']) {
                    $add_time = search($where, 'complete_time');

                    if ($add_time != 1) {
                        $query->where($add_time);
                    }
                }
                // 查询发票类型
                if ($where['invoice_title'] || $where['invoice_title'] === '0') {
                    $query->where('i.invoice_title', $where['invoice_title']);
                }
                // 查询订单号
                if ($where['order_sn']) {
                    $query->where('i.order_sn', 'like', "%{$where['order_sn']}%");
                }
            }
        }

        $list = $query -> alias('i')
                -> join('Order o', 'o.order_sn = i.order_sn')
                -> field('i.*,o.id as oid')
                -> paginate(10, false, ['query'=>request()->param()]);

        return $list;
    }
}